<?php
/**
 * Created by PhpStorm.
 * User: huliren<huliren0516@163.com>
 * Date: 2017/9/28
 * Time: 15:19
 */
define('SITE_AUTH', 'tool-mongoDB');
require('../../../common.inc.php');

use lib\core\AdminAction;
use Center\MongodbManager as Model;

class mongodbMenege extends AdminAction
{
    public function doDefault()
    {
        $smarty = $this->app->page();

        $mongo = loadconf('tool/mongo');
        if (!empty($mongo)) {
            $smarty->value('list', $mongo);
        }
        $smarty->output('tool/mongo_list.tpl');
    }

    /**
     * 搜索
     */
    public function doSearch()
    {
        $smarty = $this->app->page();

        $db = trim($_GET['db']);

        $info = Model::getCollections($db);

        $smarty->value('info', $info);
        $smarty->value('db', $db);
        $smarty->output('tool/mongo_db_list.tpl');
    }

    /**
     * 删除
     */
    public function doDelete(){
        $db = $_GET['db'];
        $name = $_GET['collection'];
        $res = Model::deleteCollection($db,$name);
        
        if($res){
            $this->output(['type'=>'yes']);
        }else{
            $this->output(['type'=>'no']);
        }

    }
}

$app->run();